<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="fb-login">fb login 1</button>
    <button id="fb-login2">fb login 3</button>

    <fb:login-button
      scope="public_profile,email,instagram_basic,pages_show_list"
      onlogin="checkLoginState();"
    >
    </fb:login-button>

    <div id="res"></div>
    <div id="res2"></div>
    <script>
      window.fbAsyncInit = function () {
        FB.init({
          appId: "5174743702629297",
          cookie: true,
          xfbml: false,
          version: "v17.0",
        });

        FB.AppEvents.logPageView();
      };

      (function (d, s, id) {
        var js,
          fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {
          return;
        }
        js = d.createElement(s);
        js.id = id;
        js.src = "https://connect.facebook.net/en_US/sdk/debug.js";
        fjs.parentNode.insertBefore(js, fjs);
      })(document, "script", "facebook-jssdk");

      function checkLoginState() {
        FB.getLoginStatus(function (response) {
          document.querySelector("#res").innerHTML = JSON.stringify(
            response,
            null,
            2
          );
        });
      }

      document.querySelector("#res2").innerHTML =
        navigator.userAgent.toLowerCase();

      document.querySelector("#fb-login").addEventListener("click", () => {
        FB.login(
          (res) => {
            if (res.status === "connected") {
              // 用户已经登录，重定向到主页
              window.location.href = "/";
            } else {
              // 用户没有登录，显示错误消息
              alert("Facebook登录失败，请重试。");
            }
          },
          { scope: "public_profile,email" }
        );
      });

      document.querySelector("#fb-login2").addEventListener("click", () => {
        window.open(
          "https://www.facebook.com/v17.0/dialog/oauth?client_id=1813852259031513&redirect_uri=https://gitwjh.gitee.io/pages/"
        );
      });

      function handleResponse(response) {
        FB.api(`/me?fields=email,picture,first_name,last_name`, (response) => {
          console.log(response, 111);
        });
      }
    </script>

    <script id="debug-script">
      var script = document.createElement("script");
      script.src = "https://unpkg.com/vconsole@latest/dist/vconsole.min.js";
      script.onload = function () {
        new window.VConsole();
      };
      document.head.appendChild(script);
    </script>
  </body>
</html>
